package logic

import (
	"context"
	"shopping-cart/cartrpc/cartrpc"

	"shopping-cart/api/internal/svc"
	"shopping-cart/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCartAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartAddLogic {
	return &CartAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CartAddLogic) CartAdd(req *types.CartAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	add, err := l.svcCtx.CartRpc.CartAdd(l.ctx, &cartrpc.CartAddRequest{
		ShopId:   req.ShopId,
		Quantity: req.Quantity,
		Money:    float32(req.Money),
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    0,
		}, nil
	}
	return &types.Response{
		Message: "添加成功",
		Data:    add,
		Code:    200,
	}, nil
}
